package com.example.qihuibao.dao

import androidx.room.TypeConverter
import com.example.qihuibao.bean.*
import com.example.qihuibao.utils.extension.genericType
import com.example.qihuibao.utils.extension.getList
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import java.lang.reflect.Type


class Converters {
    companion object {
        val gson = Gson()
    }

    @TypeConverter
    fun objectToString1(list: List<String>?): String? {
        return gson.toJson(list)
    }

    @TypeConverter
    fun stringToObject1(json: String?): List<String?>? {
        val listType: Type = object : TypeToken<List<String?>?>() {}.type
        return gson.fromJson(json, listType)
    }

    @TypeConverter
    fun objectToString2(list: List<EmpType?>?): String? {
        return gson.toJson(list)
    }

    @TypeConverter
    fun stringToObject2(json: String?): List<EmpType?>? {
        val listType: Type = object : TypeToken<List<EmpType?>?>() {}.type
        return gson.fromJson(json, listType)
    }

    @TypeConverter
    fun stringToObject3(json: String?): List<Cant?>? {
        val listType: Type = object : TypeToken<List<Cant?>?>() {}.type
        return gson.fromJson(json, listType)
    }

    @TypeConverter
    fun objectToString3(list: List<Cant?>?): String? {
        return gson.toJson(list)
    }

    @TypeConverter
    fun objectToString4(list: List<ETicketType?>?): String? {
        return gson.toJson(list)
    }

    @TypeConverter
    fun stringToObject4(json: String?): List<ETicketType?>? {
        val listType: Type = object : TypeToken<List<ETicketType?>?>() {}.type
        return gson.fromJson(json, listType)
    }

//    @TypeConverter
//    fun objectToString5(list: List<EmpType?>?): String? {
//        return gson.toJson(list)
//    }
//
//    @TypeConverter
//    fun stringToObject5(json: String?): List<EmpType?>? {
//        val listType: Type = object : TypeToken<List<EmpType?>?>() {}.type
//        return gson.fromJson(json, listType)
//    }

    @TypeConverter
    fun objectToString6(list: List<Discount?>?): String? {
        return gson.toJson(list)
    }

    @TypeConverter
    fun stringToObject6(json: String?): List<Discount?>? {
        val listType: Type = object : TypeToken<List<Discount?>?>() {}.type
        return gson.fromJson(json, listType)
    }

    @TypeConverter
    fun objectToString7(list: List<MealSet?>?): String? {
        return gson.toJson(list)
    }

    @TypeConverter
    fun stringToObject7(json: String?): List<MealSet?>? {
        val listType: Type = object : TypeToken<List<MealSet?>?>() {}.type
        return gson.fromJson(json, listType)
    }

    @TypeConverter
    fun objectToString8(list: List<Fee?>?): String? {
        return gson.toJson(list)
    }

    @TypeConverter
    fun stringToObject8(json: String?): List<Fee?>? {
        val listType: Type = object : TypeToken<List<Fee?>?>() {}.type
        return gson.fromJson(json, listType)
    }

//    @TypeConverter
//    fun objectToString9(list: List<RspQueryDepartmentInfoBean.Department?>?): String? {
//        return gson.toJson(list)
//    }
//
//    @TypeConverter
//    fun stringToObject9(json: String?): List<RspQueryDepartmentInfoBean.Department?>? {
//        val listType: Type = object : TypeToken<List<RspQueryDepartmentInfoBean.Department?>?>() {}.type
//        return gson.fromJson(json, listType)
//    }

    @TypeConverter
    fun objectToString10(list: List<MealSetFee?>?): String? {
        return gson.toJson(list)
    }

    @TypeConverter
    fun stringToObject10(json: String?): List<MealSetFee?>? {
        val listType: Type = object : TypeToken<List<MealSetFee?>?>() {}.type
        return gson.fromJson(json, listType)
    }

//    @TypeConverter
//    fun objectToString11(list: List<EmpType?>?): String? {
//        return gson.toJson(list)
//    }
//
//    @TypeConverter
//    fun stringToObject11(json: String?): List<EmpType?>? {
//        val listType: Type = object : TypeToken<List<EmpType?>?>() {}.type
//        return gson.fromJson(json, listType)
//    }
}